package com.ssl.rms.controller.login;

import com.ssl.rms.controller.BaseController;
import com.ssl.rms.shiro.realm.UserRealm.Principal;
import com.ssl.rms.util.UserUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 描述：登录controller
 *
 * @author ssl
 * @create 2018/02/07 17:19
 */
@Controller
public class LoginController extends BaseController {

    /**
     * 首页
     *
     * @return
     */
    @RequestMapping(value = {"", "/", "index"})
    public String index() {
        return "index";
    }

    /**
     * 登录页面
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping(value = "login", method = {RequestMethod.GET, RequestMethod.POST})
    public String login(HttpServletRequest request, Model model) {
        Principal principal = UserUtils.getPrincipal();
        if (null == principal) {
            /** 没有授权用户信息，则到登录页面 */
            return "login";
        }
        /** 跳转至首页  */
        return "redirect:/index";
    }
}
